Skip to content

fix(handlers): CWE-22 path traversal in Tier 4 runtime-default template resolution - #2007

Merged
HongmingWang-Rabbit merged 1 commit into
stagingfrom
fix/cwe22-restart-template
Apr 24, 2026
Merged

fix(handlers): CWE-22 path traversal in Tier 4 runtime-default template resolution#2007
HongmingWang-Rabbit merged 1 commit into
stagingfrom
fix/cwe22-restart-template

Conversation

@molecule-ai

@molecule-ai molecule-ai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • CWE-22 path traversal in restart_template.go Tier 4: dbRuntime was joined into the template path without allowlist sanitisation
  • An attacker with a valid workspace token can set runtime to ../../../etc via PATCH /workspaces/:id (Update handler validates length + newlines only, not ..)
  • On a restart with apply_template=true, the template path escapes configsDir to an attacker-chosen host path

Fix

Call sanitizeRuntime(dbRuntime) (existing allowlist from workspace_provision.go) before filepath.Join in Tier 4. Unknown values are remapped to "langgraph" — the attacker cannot choose an arbitrary host path.

Changes

File Change
workspace-server/internal/handlers/restart_template.go sanitizeRuntime(dbRuntime) before filepath.Join; security comment explaining the CWE-22 rationale
workspace-server/internal/handlers/restart_template_test.go Two regression tests covering traversal strings falling through, and the safe langgraph-default resolution path

Test plan

  • TestResolveRestartTemplate_CWE22_TraversalRuntime_FallsThrough — 5 traversal variants must not escape configsDir
  • TestResolveRestartTemplate_CWE22_TraversalRuntime_CannotOverrideKnownRuntime — traversal string resolves langgraph-default, not attacker-chosen path
  • All existing resolveRestartTemplate tests pass

Severity

P1 / Medium-High. Precondition: attacker needs valid workspace bearer token and a directory matching the traversal string must exist on the host filesystem. Confirmed by Core Platform Lead.

🤖 Generated with Claude Code

@molecule-ai molecule-ai Bot added security Security issue — do not merge without security review P1 CWE-22 labels Apr 24, 2026
@molecule-ai
molecule-ai Bot requested a review from airenostars April 24, 2026 10:52
….Join (CWE-22)

CWE-22 path traversal in restartTemplateInput Tier 4: dbRuntime was joined
directly into the template path without sanitisation.

  runtimeTemplate := filepath.Join(configsDir, dbRuntime+"-default")

An attacker holding a workspace token could set runtime to a path-traversal
string (e.g. "../../../etc") via the PATCH /workspaces/:id Update handler,
which only validates length and newlines.  If a matching directory existed
on the host (e.g. /configs/../../../etc-default), the restart would load
files from an arbitrary host path into the workspace container.

Fix: call sanitizeRuntime(dbRuntime) — the existing allowlist in
workspace_provision.go — before filepath.Join.  Unknown values are
remapped to "langgraph", so the attacker cannot choose an arbitrary host
path.  Defense-in-depth: the path is still inside configsDir after
sanitisation.

Regression tests added:
- CWE-22 traversal strings fall through to existing-volume
- langgraph-default is used when traversal string is sanitised to langgraph

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@molecule-ai
molecule-ai Bot force-pushed the fix/cwe22-restart-template branch from 3bcdf19 to d7901bb Compare April 24, 2026 11:50
@HongmingWang-Rabbit
HongmingWang-Rabbit added this pull request to the merge queue Apr 24, 2026
Merged via the queue into staging with commit 4597ab0 Apr 24, 2026
14 checks passed
@molecule-ai

molecule-ai Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

Security Review ✅

Reviewed by Core-QA (molecule-core automated audit)

sanitizeRuntime allowlist correctly remaps all traversal variants to 'langgraph'. No injection, no path escape.

Regression coverage: 5 traversal strings tested.

Verdict: MERGEABLE. No security blockers. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CWE-22 P1 security Security issue — do not merge without security review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant